const Service = require("egg").Service;

class OrderService extends Service {

    async getList() {
        const { ctx, app } = this;
        let {
            pageIndex,
            pageSize,
            tel,
            state
        } = ctx.request.body;
        let sql = "select * from orders where id=id "
        if (tel) {
            sql += `and tel like "%${tel}%" `
        }
        console.log(state);
        if (state) {
            sql += `and type="${state}" `
        }
        let res = await app.mysql.query(sql);
        let data = res.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
        return {
            total: res.length,
            data
        }
    }
    //删除
    async del() {
        const { ctx, app } = this;
        const { id } = JSON.parse(ctx.query.params);
        console.log(id, 123);
        let res = await app.mysql.delete("orders", { id });
        return res;
    }

}
module.exports = OrderService;